#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPixmap>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //存放要显示的图片
    piclist.append("C:/Users/Administrator/Desktop/share/image/1.jpg");
    piclist.append("C:/Users/Administrator/Desktop/share/image/2.png");
    piclist.append("C:/Users/Administrator/Desktop/share/image/3.jpeg");
    piclist.append("C:/Users/Administrator/Desktop/share/image/4.jpg");

    n=0;
    //初始化定时器
    timer=new QTimer(this);

    //设置1秒定时时间
    timer->setInterval(1000);

    //关联timeout信号
    connect(timer,SIGNAL(timeout()),this,SLOT(fun()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

//启动定时器，显示图片
void MainWindow::on_pushButton_clicked()
{
    timer->start();
}
//定时器的槽函数
void MainWindow::fun()
{
    //在标签上显示图片
    QPixmap map(piclist.at(n));
    //由于我只有四张图片，n不能无限制++
    if(n<piclist.size()-1)
        n++;
    else
        n=0;
    //调整图片大小
    map.scaled(ui->label->width(),ui->label->height());
    //配置生效
    ui->label->setScaledContents(true);
    ui->label->setPixmap(map);
}
//关闭定时器
void MainWindow::on_pushButton_2_clicked()
{
    timer->stop();
}
